<!DOCTYPE html>
<html><head>
<meta name="viewport" content="width=device-width" />
<style type="text/css">
  body {
    margin: 0;
  }

  header {
    width: 100%;
    padding: 10px 0 0 0;
    margin: 0;
    background: white;
    font: 12px "Lucida Grande", sans-serif;
    border-bottom: 1px solid #dedede;
    overflow: hidden;
  }

  dl {
    margin: 0 0 10px 0;
    padding: 0;
  }

  dt {
    width: 80px;
    padding: 1px;
    float: left;
    clear: left;
    text-align: right;
    color: #7f7f7f;
  }

  dd {
    margin-left: 90px; /* 80px + 10px */
    padding: 1px;
  }

  iframe {
    border: 0;
    width: 100%;
    height: 800px;
  }
</style>
</head>

<body>
<header>
  <dl>
    <% if mail.respond_to?(:smtp_envelope_from) && Array(mail.from) != Array(mail.smtp_envelope_from) %>
      <dt>SMTP-From:</dt>
      <dd><%= mail.smtp_envelope_from %></dd>
    <% end %>

    <% if mail.respond_to?(:smtp_envelope_to) && mail.to != mail.smtp_envelope_to %>
      <dt>SMTP-To:</dt>
      <dd><%= mail.smtp_envelope_to %></dd>
    <% end %>

    <dt>From:</dt>
    <dd><%= Rack::Utils.escape_html(mail.header['from'].to_s) %></dd>

    <% if mail.reply_to %>
      <dt>Reply-To:</dt>
      <dd><%= Rack::Utils.escape_html(mail.header['reply-to'].to_s) %></dd>
    <% end %>

    <dt>To:</dt>
    <dd><%= Rack::Utils.escape_html(mail.header['to'].to_s) %></dd>

    <% if mail.cc %>
      <dt>CC:</dt>
      <dd><%= Rack::Utils.escape_html(mail.header['cc'].to_s) %></dd>
    <% end %>

    <dt>Date:</dt>
    <dd><%= Time.now.strftime("%b %e, %Y %I:%M:%S %p %Z") %></dd>

    <dt>Subject:</dt>
    <dd><strong><%= mail.subject %></strong></dd>

    <% unless mail.attachments.nil? || mail.attachments.empty? %>
      <dt>Attachments:</dt>
      <dd>
        <%= Rack::Utils.escape_html mail.attachments.map { |a| a.respond_to?(:original_filename) ? a.original_filename : a.filename }.inspect %>
      </dd>
    <% end %>

    <% if mail.multipart? %>
      <dd>
        <select onchange="document.getElementsByName('messageBody')[0].src=this.options[this.selectedIndex].value;">
          <option value="?part=text%2Fhtml">View as HTML email</option>
          <option value="?part=text%2Fplain">View as plain-text email</option>
        </select>
      </dd>
    <% end %>
  </dl>
</header>

<iframe seamless name="messageBody" src="<%= part_url %>"></iframe>

</body>
</html>
